/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package questionbook.model;

import java.util.Date;
import org.openrdf.model.Literal;
import org.openrdf.model.URI;

/**
 * Represents an given Answer
 *
 *
 * @author stefanstift
 */
public class Answer extends StandardModel {

    /**
     *  The content of the Asnwer
     */
    private String text;
    /**
     *  The User who wrote the Answer
     */
    private Person answerer;
    /**
     *  The Type of the Answer (sure, think)
     */
    private AnswerType answerType;
    /**
     * The Class of the Answer (e.g. SuperAnswer, TrustAnswer,....)
     */
    private AnswerClass answerClass;
    /**
     *  The Create date of the Answer
     */
    private Date createdAt;

    /**
     * Creates new Answer with specified URI
     *
     * @param uri
     */
    public Answer(URI uri) {
        super(uri);
    }

    /**
     * Creates new Answer with specified String representing a URI
     *
     * @param uri
     */
    public Answer(String uri) {
        super(uri);
    }

    /**
     *
     * @return the Content of the Answer as a Literal
     */
    public Literal getTextLiteral() {
        return this.getStringLiteral(text);
    }

    /**
     *
     * @return the content of the Answer
     */
    public String getText() {
        return text;
    }

    /**
     * Sets the content of the Answer
     *
     * @param text
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     *
     * @return  the Type of the Answer (sure, think)
     */
    public AnswerType getAnswerType() {
        return answerType;
    }

    /**
     * Sets the Type of the Answer (sure, think)
     * @param answerType
     */
    public void setAnswerType(AnswerType answerType) {
        this.answerType = answerType;
    }

    /**
     *
     * @return the User who wrote the Answer
     */
    public Person getAnswerer() {
        return answerer;
    }

    /**
     * Sets the User who worte the Answer
     *
     * @param answerer
     */
    public void setAnswerer(Person answerer) {
        this.answerer = answerer;
    }

    /**
     *
     * @return the Class of the Answer (e.g. SuperAnswer, TrustAnswer,....)
     */
    public AnswerClass getAnswerClass() {

        if(this.answerClass == null)
            this.answerClass = AnswerClass.StdAnswer;

        return answerClass;
    }


    /**
     * Sets the Class of the Answer (e.g. SuperAnswer, TrustAnswer,....)
     *
     * @param answerClass
     */
    public void setAnswerClass(AnswerClass answerClass) {
        this.answerClass = answerClass;
    }

    /**
     *
     * @return Timestamp of Create-Date as Long-Literal
     */
    public Literal getCreatedAtLiteral() {
        return this.getLongLiteral(this.createdAt.getTime());
    }

    /**
     *
     * @return Date-Object of the Create-Date
     */
    public Date getCreatedAt() {
        return createdAt;
    }

    /**
     *
     * @return String-Representation of the Create-Date
     */
    public String getCreatedAtString() {
        return this.format.format(createdAt);
    }

    /**
     * Sets the Create-Date with a Timestamp-String
     *
     * @param timestamp
     */
    public void setCreatedAt(String timestamp) {
        this.createdAt = new Date(Long.parseLong(timestamp));
    }

    /**
     * Sets the Create-Date with a Date-Object
     *
     * @param createdAt
     */
    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    /**
     *
     * @return the CSS Style-Property depending on the Class of the Answer
     */
    public String getStyle()
    {
        if(this.answerClass == null)
            return "border-color: white; border-style: solid; border-width: 2px";
        if(this.answerClass == AnswerClass.IgnoreAnswer)
            return  "border-color: red; border-style: solid; border-width: 2px";
        if(this.answerClass == AnswerClass.BadAnswer)
            return  "border-color: lightsalmon; border-style: solid; border-width: 2px";
        if(this.answerClass == AnswerClass.DoubtAnswer)
            return   "border-color: yellow; border-style: solid; border-width: 2px";
        if(this.answerClass == AnswerClass.StdAnswer)
            return "border-color: white; border-style: solid; border-width: 2px";
        if(this.answerClass == AnswerClass.TrustAnswer)
            return "border-color: blue; border-style: solid; border-width: 2px";
        if(this.answerClass == AnswerClass.SuperAnswer)
            return "border-color: lightgreen; border-style: solid; border-width: 2px";
        if(this.answerClass == AnswerClass.ExpertAnswer)
            return "border-color: green; border-style: solid; border-width: 2px";

        return "border-color: white; border-style: solid; border-width: 2px";
    }

}
